package com.handu.luna.core.domain.promotion;

import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.validation.constraints.Size;

import com.handu.luna.core.domain.BasePersistentDomain;

import java.util.Date;


/**
 * 优惠活动
 * @author zhangwen
 *
 */

@SuppressWarnings("rawtypes")
@MappedSuperclass
public class Promotion extends BasePersistentDomain<PromotionRepository> {

    {
        String name = this.getClass().getName();
        switch (name) {
            case "com.handu.luna.core.domain.promotion.SecKillGroupBuy" :
                this.type = PromotionType.SECKILLGROUPBUY;
                break;
            case "com.handu.luna.core.domain.promotion.SalesPromtion" :
                this.type = PromotionType.SALES;
                break;
            case "com.handu.luna.core.domain.promotion.Activities" :
                this.type = PromotionType.ACTIVITY;
                break;
            case "com.handu.luna.core.domain.promotion.CouponPromotion":
                this.type = PromotionType.COUPON;
                break;
            case "com.handu.luna.core.domain.promotion.RedPacketPromotion":
                this.type = PromotionType.REDPACKET;
                break;
            case "com.handu.luna.core.domain.promotion.CashCardPromotion":
                this.type = PromotionType.CASHCARD;
                break;
            case "com.handu.luna.core.domain.promotion.PostForFreeActivity":
                this.type = PromotionType.PFF;
                break;
            default:

        }
    }

    /**
	 * 优惠类型，
	 */
	public enum PromotionType{

        SECKILLGROUPBUY("团购秒杀"),SALES("促销活动"),ACTIVITY("优惠活动"),
        COUPON("优惠券"),REDPACKET("红包"),CASHCARD("现金卡"),
        POSTCARD("包邮卡"),PFF("包邮活动"),MATCH("搭配套餐");

        public String description;
        PromotionType(String description) {
            this.description = description;
        }
	}

	public enum PromotionStatus{
		UNACTIVATED("即将开始"),ACTIVATING("正在进行"),ACTIVATED("已过期");
        public String description;
        PromotionStatus(final String description) {
         this.description = description;
        }
	}

	
    @Transient private String status;
    public PromotionType type;
    @Size(min = 1,max=250,message = "名称字符个数应在1到250之间")
    public String name;

    public PromotionType getType() {
        return type;
    }

    public void setType(PromotionType type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSucessFlashMessage(String message){
        String messagePrefix = (null==this.getId() ?"添加" : "修改");
        return messagePrefix + message + "成功";
    }

    public String getStatus() {
        return initStatus(null,null);
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String initStatus(Date startDate,Date endDate) {
        Date now = new Date();
        if(startDate != null && endDate != null) {
            if(now.compareTo(startDate)==-1){
			status =  "<font color='#006400'> 【"+PromotionStatus.UNACTIVATED.description+"】</font>";
            }else if(endDate.compareTo(now)==-1){
                status = "<font color='#696969'>【"+PromotionStatus.ACTIVATED.description+"】</font>";
            }else{
                status = "<font color='#8B0000'>【"+PromotionStatus.ACTIVATING.description+"】</font>";
            }
        }else {
            status = "";
        }
        return status;
    }

}
